/*
 * =====================================================================================
 *
 *       Filename:  MySerial.h
 *
 *    Description:  this is a serial class of mine
 *
 *        Version:  1.0
 *        Created:  2012年04月09日 10时31分36秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Michael lee
 *        Company:  
 *
 * =====================================================================================
 */

#ifndef MYSERIAL_H
#define MYSERIAL_H

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/stat.h>

const int SERIAL_BUF_SIZE =512;

class MySerial
{
public:
    MySerial();
    ~MySerial();
    int openPort(int comport);
    void closePort();
    int setOpt(int nSpeed, int nBits, char cEvent,int nStop) const;
    int writeData(const unsigned char *data,int writeLen);
    int readData(unsigned char *buf,int readLen,int nTimeOutMs);
    int mFd;
private:
    //int mFd;
    fd_set mRd;
    unsigned char mReadBuf[SERIAL_BUF_SIZE];
    unsigned char mWriteBuf[SERIAL_BUF_SIZE];
};

#endif
